In [1]:
import cv2
In [2]:
import matplotlib.pyplot as plt
In [3]:
img1 = cv2.imread('demo1.jpg', cv2.IMREAD_GRAYSCALE)
In [4]:
img2 = cv2.imread('nature.jpg', cv2.IMREAD_GRAYSCALE)
In [5]:
plt.figure(figsize=(20,15))
Out[5]:
In [6]:
plt.subplot(1,2,1)
Out[6]:
In [7]:
plt.imshow(img1, cmap='gray')
Out[7]:
In [8]:
plt.subplot(1,2,2)
Out[8]:
In [9]:
plt.imshow(img2, cmap='gray')
Out[9]:
In [10]:
plt.show()
In [11]:
plt.figure(figsize=(20,15))
Out[11]:
In [12]:
plt.subplot(1,3,1)
Out[12]:
In [13]:
img_sum = img1 + img2
plt.imshow(img_sum, cmap='gray')
In [14]:
print('Image type:', img_sum.dtype)
In [15]:
plt.title('1. A + B')
Out[15]:
In [16]:
plt.imshow(img_sum, cmap='gray')
Out[16]:
In [17]:
plt.subplot(1,3,2)
Out[17]:
In [18]:
img_avg = (img1 + img2)/2
In [19]:
plt.title('2. (A + B)/2')
Out[19]:
In [20]:
plt.imshow(img_avg, cmap='gray')
Out[20]:
In [21]:
plt.subplot(1,3,3)
Out[21]:
In [22]:
img_avg_alt = img1/2 + img2/2
In [23]:
plt.title('3. A/2 + B/2')
Out[23]:
In [24]:
plt.imshow(img_avg_alt, cmap='gray')
Out[24]:
In [25]:
plt.show()